package ip

import (
	"go-fiber-ip2region/model/common/response"
	"go-fiber-ip2region/model/ip/request"
	ipResponse "go-fiber-ip2region/model/ip/response"

	"github.com/gofiber/fiber/v2"
)

type IpInfoApi struct{}

// @Tags ip
// @Summary 获取ip详情
// @Success 200 {object} ipResponse.IpInfoReq
// @Param ip path string true "ip地址"
// @Router /ip/{ip} [get]
func (v *IpInfoApi) GetIpInfo(c *fiber.Ctx) error {
	ip := c.Params("ip")

	ipReq := &request.IpInfoReq{Ip: ip}

	err := systemService.Validate(*ipReq)

	if err != nil {
		return c.Status(fiber.StatusBadRequest).JSON(response.ErrorResponse{Message: string(err.Error())})
	}

	var ipInfo ipResponse.IpInfoReq
	ipInfo, err = ipService.GetIpInfo(ip)

	if err != nil {
		return c.Status(fiber.StatusBadGateway).JSON(response.ErrorResponse{Message: string(err.Error())})
	}

	return c.JSON(ipInfo)
}
